/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewsEditor.java
 *
 * Created on 19-mar-2009, 11:25:27
 */

package grupb.upf.gui;

import grupb.upf.XMLObjects.Author;
import grupb.upf.XMLObjects.New;
import grupb.upf.XMLObjects.NewBody;
import grupb.upf.XMLObjects.Photo;
import grupb.upf.XMLObjects.PhotoNew;
import grupb.upf.XMLObjects.Tag;
import grupb.upf.XMLObjects.Tagging;
import grupb.upf.XMLObjects.impl.PersonalTag;
import grupb.upf.XMLObjects.impl.PredefinedTag;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author usuario
 */
public class NewsEditor extends javax.swing.JPanel {

    /**
     * The logger. A new logger <code>grupb.upf.gui.NewsEditor</code>
     * is created to add the logs of this NewsEditor
     */
    private static final Log LOG = LogFactory.getLog(NewsEditor.class);
    /**
     * The principal GUI.
     */
    private P2Piki p2piki;
    /**
     * The list of tags.
     */
    private List < Tag > auxTagsList = new Vector();
    /**
     * The list of tags.
     */
    private List < Author > auxAuthorsList = new Vector();
    /**
     * The default list model of edited tags.
     */
    private DefaultListModel editedTagsModel = new DefaultListModel();
    /**
     * The default list model of edited tags.
     */
    private DefaultListModel authorsModel = new DefaultListModel();
    /**
     * The list of Taxonomies.
     */
    private List taxonomies;
    /**
     * The new.
     */
    private New nw;
    /**
     * The type of photos format accepted.
     */
    private static final String [] PHOTO_FORMATS =
    {"jpg", "jpeg", "gif", "png"};

    /** Creates new form NewsEditor */
    public NewsEditor(final P2Piki p2p) {
        this.p2piki = p2p;
        initComponents();
    }
    /**
     * Method to set a new.
     * @param newNew the new to edit or create.
     */
    public void setNew(final New newNew) {
        nw = newNew;
        initCategories(taxonomies);
        getProperties();
        p2piki.repaint();
    }
    public void updateNewProperties() {
        nw.setTitle(title.getText().trim());
        nw.setSubtitle(subtitle.getText().trim());
        nw.setSource(source.getText().trim());
        nw.setAuthors(auxAuthorsList);
        final List predefinedTags = new Vector();
        final List personalTags = new Vector();
        for (int i = 0; i < auxTagsList.size(); i++) {
            if (auxTagsList.get(i) instanceof PredefinedTag) {
                predefinedTags.add(auxTagsList.get(i));
            } else if (auxTagsList.get(i) instanceof PersonalTag) {
                personalTags.add(auxTagsList.get(i));
            }
        }
        nw.getTags().setPredefinedTags(predefinedTags);
        nw.getTags().setPersonalTags(personalTags);

        //Falta el body...
        String b = "<paragraph>" + body.getText().trim() + "</paragraph>";
        b = b.replaceAll("\n", "</paragraph><paragraph>");
        b = b.replaceAll("<photo", "</paragraph><photo");
        b = b.replaceAll("</photo>", "</photo><paragraph>");
        b = b.replaceAll("<paragraph></paragraph>", "");
        NewBody nb = new grupb.upf.XMLObjects.impl.NewBody();
        nb.addElement(b);
        nw.setBody(nb);
    }
    /**
     * Method to get the properties and show them.
     */
    private void getProperties() {
        if (nw != null) {
            body.setText("");
            title.setText(nw.getTitle());
            subtitle.setText(nw.getSubtitle());
            source.setText(nw.getSource());
            List e = nw.getBody().getElements();
            for (int i = 0; i < e.size(); i++) {
                if (e.get(i) instanceof String) {
                    String in = (String) e.get(i) + "\n";
                    in = in.replaceAll("<paragraph>", "");
                    in = in.replaceAll("</paragraph>", "\n");
                    in = in.replaceAll("</photo>", "</photo>\n");
                    body.append(in);
                } else if (e.get(i) instanceof PhotoNew) {
                    PhotoNew pn = (PhotoNew) e.get(i);
                    body.append("<photo id=\""
                            + pn.getID() + "\"></photo>\n");
                }
            }
            Tagging tags = nw.getTags();
            List < Tag > listOfTags = tags.getPersonalTags();
            List < Author > listOfAuthors = nw.getAuthors();
            auxAuthorsList = new Vector();
            auxTagsList = new Vector();
            authorsModel.removeAllElements();
            editedTagsModel.removeAllElements();
            for (int i = 0; i < listOfTags.size(); i++) {
                auxTagsList.add(listOfTags.get(i));
                editedTagsModel.addElement(
                        (String) listOfTags.get(i).getTag());
            }
            listOfTags = tags.getPredefinedTags();
            for (int i = 0; i < listOfTags.size(); i++) {
                auxTagsList.add(listOfTags.get(i));
                editedTagsModel.addElement(
                        (String) listOfTags.get(i).getTag());
            }
            for (int i = 0; i < listOfAuthors.size(); i++) {
                auxAuthorsList.add(listOfAuthors.get(i));
                authorsModel.addElement((String) listOfAuthors.get(i).getName()
                        + " " + listOfAuthors.get(i).getSurname());
            }
        } else {
            nw = new grupb.upf.XMLObjects.impl.New();
            nw.setAuthors(new Vector());
            Tagging tags = new grupb.upf.XMLObjects.impl.Tagging();
            tags.setPersonalTags(new Vector());
            tags.setPredefinedTags(new Vector());
            nw.setTags(tags);
            nw.setID(-1);
            title.setText("");
            subtitle.setText("");
            source.setText("");
            body.setText("");
            auxTagsList = new Vector();
            editedTagsModel.removeAllElements();
            authorsModel.removeAllElements();
        }
    }
    /**
     * Method to set up the categories of the ontologies, we receive it from
     * the main class.
     * @param t the complete t
     */
    public void initCategories(final List t) {
        taxonomies = t;
        List tax;
        categoriesComboBox.removeAllItems();
        categoriesComboBox.addItem("Choose a category");
        for (int i = 0; i < t.size(); i++) {
            tax = (List) t.get(i);
            categoriesComboBox.addItem((String) tax.get(0));
        }
    }

    /**
     * Method to delete a new.
     */
    public void deleteNew() {
        if (nw != null && nw.getID() != -1) {
            if (p2piki.deleteNew(nw.getID())) {
                p2piki.viewListNews();
                p2piki.addInfo("New deleted correctly.");
            } else {
                p2piki.addError("Error deleting the new.");
            }
        } else {
            p2piki.addError("The new isn't added to the DB yet.");
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        ontologiesPopupMenu = new javax.swing.JPopupMenu();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        deleteInternalFrame = new javax.swing.JInternalFrame();
        deleteYesButton = new javax.swing.JButton();
        deleteNoButton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        newsEditorPanel = new javax.swing.JPanel();
        optionsPanel = new javax.swing.JPanel();
        newsListButton = new javax.swing.JButton();
        deleteNewButton = new javax.swing.JButton();
        addNewButton = new javax.swing.JButton();
        generalPanel = new javax.swing.JPanel();
        titleLabel = new javax.swing.JLabel();
        title = new javax.swing.JTextField();
        subjectLabel = new javax.swing.JLabel();
        subtitle = new javax.swing.JTextField();
        source = new javax.swing.JTextField();
        sourceLabel = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        addTagTabbedPane1 = new javax.swing.JTabbedPane();
        personalTagPanel1 = new javax.swing.JPanel();
        addTagTextField = new javax.swing.JTextField();
        addPersonalTagButton = new javax.swing.JButton();
        ontologyTagPanel1 = new javax.swing.JPanel();
        addOntologyTagButton = new javax.swing.JButton();
        addOntologyTagTextField = new javax.swing.JTextField();
        categoryLabel1 = new javax.swing.JLabel();
        categoriesComboBox = new javax.swing.JComboBox();
        editedTagsScrollPane1 = new javax.swing.JScrollPane();
        editedTagsList = new javax.swing.JList();
        deleteTagButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        body = new javax.swing.JTextArea();
        authorsPanel = new javax.swing.JPanel();
        editedTagsScrollPane2 = new javax.swing.JScrollPane();
        authorsList = new javax.swing.JList();
        deleteAuthorButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        surnameTextField = new javax.swing.JTextField();
        addAuthorButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        accountTextField = new javax.swing.JTextField();
        addPhotoButton = new javax.swing.JButton();
        updateButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        ontologiesPopupMenu.setAutoscrolls(true);
        ontologiesPopupMenu.setMaximumSize(new java.awt.Dimension(260, 100));

        setBackground(new java.awt.Color(255, 255, 255));
        setMaximumSize(new java.awt.Dimension(680, 489));
        setMinimumSize(new java.awt.Dimension(680, 489));

        deleteInternalFrame.setTitle("Delete a new");
        deleteInternalFrame.setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/p2pikiLogo.png"))); // NOI18N
        deleteInternalFrame.setMaximumSize(new java.awt.Dimension(200, 114));
        deleteInternalFrame.setMinimumSize(new java.awt.Dimension(200, 114));

        deleteYesButton.setText("Yes");
        deleteYesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteYesButtonActionPerformed(evt);
            }
        });

        deleteNoButton.setText("No");
        deleteNoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteNoButtonActionPerformed(evt);
            }
        });

        jLabel3.setText("Are you sure to delete this new?");

        javax.swing.GroupLayout deleteInternalFrameLayout = new javax.swing.GroupLayout(deleteInternalFrame.getContentPane());
        deleteInternalFrame.getContentPane().setLayout(deleteInternalFrameLayout);
        deleteInternalFrameLayout.setHorizontalGroup(
            deleteInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(deleteInternalFrameLayout.createSequentialGroup()
                .addGroup(deleteInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(deleteInternalFrameLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3))
                    .addGroup(deleteInternalFrameLayout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(deleteYesButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteNoButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        deleteInternalFrameLayout.setVerticalGroup(
            deleteInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, deleteInternalFrameLayout.createSequentialGroup()
                .addContainerGap(24, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(deleteInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteYesButton)
                    .addComponent(deleteNoButton))
                .addContainerGap())
        );

        deleteInternalFrame.setBounds(200, 150, 190, 110);
        jDesktopPane1.add(deleteInternalFrame, javax.swing.JLayeredPane.POPUP_LAYER);
        deleteInternalFrame.getAccessibleContext().setAccessibleName("Delete new");

        newsEditorPanel.setBackground(new java.awt.Color(255, 255, 255));
        newsEditorPanel.setMaximumSize(new java.awt.Dimension(670, 490));
        newsEditorPanel.setPreferredSize(new java.awt.Dimension(670, 490));

        optionsPanel.setBackground(new java.awt.Color(255, 255, 255));
        optionsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Options", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        newsListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/listNews.png"))); // NOI18N
        newsListButton.setText("List of news");
        newsListButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newsListButtonActionPerformed(evt);
            }
        });

        deleteNewButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/deleteNew.png"))); // NOI18N
        deleteNewButton.setText("Delete new");
        deleteNewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteNewButtonActionPerformed(evt);
            }
        });

        addNewButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/editNew.png"))); // NOI18N
        addNewButton.setText("Add new    ");
        addNewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addNewButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout optionsPanelLayout = new javax.swing.GroupLayout(optionsPanel);
        optionsPanel.setLayout(optionsPanelLayout);
        optionsPanelLayout.setHorizontalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addNewButton, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                    .addComponent(deleteNewButton, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                    .addComponent(newsListButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE))
                .addContainerGap())
        );
        optionsPanelLayout.setVerticalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(newsListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(addNewButton, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deleteNewButton, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        generalPanel.setBackground(new java.awt.Color(255, 255, 255));
        generalPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "General", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        titleLabel.setText("Title");

        subjectLabel.setText("Subtitle");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, body, org.jdesktop.beansbinding.ObjectProperty.create(), subtitle, org.jdesktop.beansbinding.BeanProperty.create("nextFocusableComponent"));
        bindingGroup.addBinding(binding);

        sourceLabel.setText("Source");

        javax.swing.GroupLayout generalPanelLayout = new javax.swing.GroupLayout(generalPanel);
        generalPanel.setLayout(generalPanelLayout);
        generalPanelLayout.setHorizontalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(subjectLabel)
                    .addComponent(titleLabel))
                .addGap(14, 14, 14)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(generalPanelLayout.createSequentialGroup()
                        .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(sourceLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(source, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(subtitle, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        generalPanelLayout.setVerticalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPanelLayout.createSequentialGroup()
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(titleLabel)
                    .addComponent(source, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sourceLabel)
                    .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(subjectLabel)
                    .addComponent(subtitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tags edition", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        addTagTabbedPane1.setMaximumSize(new java.awt.Dimension(211, 180));
        addTagTabbedPane1.setMinimumSize(new java.awt.Dimension(211, 180));

        personalTagPanel1.setBackground(new java.awt.Color(255, 255, 255));
        personalTagPanel1.setMaximumSize(new java.awt.Dimension(209, 152));
        personalTagPanel1.setMinimumSize(new java.awt.Dimension(209, 152));

        addPersonalTagButton.setText("Add Tag");
        addPersonalTagButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPersonalTagButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout personalTagPanel1Layout = new javax.swing.GroupLayout(personalTagPanel1);
        personalTagPanel1.setLayout(personalTagPanel1Layout);
        personalTagPanel1Layout.setHorizontalGroup(
            personalTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(personalTagPanel1Layout.createSequentialGroup()
                .addGroup(personalTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(personalTagPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(addTagTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))
                    .addGroup(personalTagPanel1Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(addPersonalTagButton, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        personalTagPanel1Layout.setVerticalGroup(
            personalTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(personalTagPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addTagTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                .addComponent(addPersonalTagButton)
                .addContainerGap())
        );

        addTagTabbedPane1.addTab("Personal Tag", personalTagPanel1);

        ontologyTagPanel1.setBackground(new java.awt.Color(255, 255, 255));
        ontologyTagPanel1.setMaximumSize(new java.awt.Dimension(209, 152));
        ontologyTagPanel1.setMinimumSize(new java.awt.Dimension(209, 152));

        addOntologyTagButton.setText("Add Tag");
        addOntologyTagButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addOntologyTagButtonActionPerformed(evt);
            }
        });

        addOntologyTagTextField.setEnabled(false);
        addOntologyTagTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                addOntologyTagTextFieldKeyReleased(evt);
            }
        });

        categoryLabel1.setFont(new java.awt.Font("Tahoma", 0, 10));
        categoryLabel1.setText("Category");

        categoriesComboBox.setFont(new java.awt.Font("Tahoma", 0, 10));
        categoriesComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Choose a category" }));
        categoriesComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                categoriesComboBoxItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout ontologyTagPanel1Layout = new javax.swing.GroupLayout(ontologyTagPanel1);
        ontologyTagPanel1.setLayout(ontologyTagPanel1Layout);
        ontologyTagPanel1Layout.setHorizontalGroup(
            ontologyTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ontologyTagPanel1Layout.createSequentialGroup()
                .addGroup(ontologyTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ontologyTagPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(ontologyTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(ontologyTagPanel1Layout.createSequentialGroup()
                                .addComponent(categoryLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(categoriesComboBox, 0, 112, Short.MAX_VALUE))
                            .addComponent(addOntologyTagTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)))
                    .addGroup(ontologyTagPanel1Layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(addOntologyTagButton, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        ontologyTagPanel1Layout.setVerticalGroup(
            ontologyTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ontologyTagPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addOntologyTagTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ontologyTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(categoryLabel1)
                    .addComponent(categoriesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(39, 39, 39)
                .addComponent(addOntologyTagButton)
                .addGap(101, 101, 101))
        );

        addTagTabbedPane1.addTab("Ontology Tag", ontologyTagPanel1);

        editedTagsScrollPane1.setMaximumSize(new java.awt.Dimension(144, 130));
        editedTagsScrollPane1.setMinimumSize(new java.awt.Dimension(144, 130));
        editedTagsScrollPane1.setPreferredSize(new java.awt.Dimension(144, 130));

        editedTagsList.setModel(editedTagsModel);
        editedTagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        editedTagsList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                editedTagsListValueChanged(evt);
            }
        });
        editedTagsList.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                editedTagsListFocusLost(evt);
            }
        });
        editedTagsScrollPane1.setViewportView(editedTagsList);

        deleteTagButton.setText("Delete Tag");
        deleteTagButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteTagButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addTagTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(deleteTagButton, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
                    .addComponent(editedTagsScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(editedTagsScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deleteTagButton))
            .addComponent(addTagTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, Short.MAX_VALUE)
        );

        body.setColumns(20);
        body.setRows(5);
        body.setMaximumSize(new java.awt.Dimension(164, 94));
        body.setMinimumSize(new java.awt.Dimension(164, 94));
        jScrollPane1.setViewportView(body);

        authorsPanel.setBackground(new java.awt.Color(255, 255, 255));
        authorsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Authors edition", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        editedTagsScrollPane2.setMaximumSize(new java.awt.Dimension(144, 130));
        editedTagsScrollPane2.setMinimumSize(new java.awt.Dimension(144, 130));
        editedTagsScrollPane2.setPreferredSize(new java.awt.Dimension(144, 130));

        authorsList.setModel(authorsModel);
        authorsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        authorsList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                authorsListValueChanged(evt);
            }
        });
        authorsList.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                authorsListFocusLost(evt);
            }
        });
        editedTagsScrollPane2.setViewportView(authorsList);

        deleteAuthorButton.setText("Delete Author");
        deleteAuthorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteAuthorButtonActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Name");

        addAuthorButton.setText("Add Author");
        addAuthorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addAuthorButtonActionPerformed(evt);
            }
        });

        jLabel2.setText("Surname");

        jLabel4.setText("Account");

        accountTextField.setText("@gmail.com");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(addAuthorButton))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(surnameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(accountTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(9, 9, 9)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(surnameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addGap(1, 1, 1)
                .addComponent(accountTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(addAuthorButton)
                .addContainerGap())
        );

        javax.swing.GroupLayout authorsPanelLayout = new javax.swing.GroupLayout(authorsPanel);
        authorsPanel.setLayout(authorsPanelLayout);
        authorsPanelLayout.setHorizontalGroup(
            authorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, authorsPanelLayout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(authorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(deleteAuthorButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(editedTagsScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, Short.MAX_VALUE))
                .addContainerGap())
        );
        authorsPanelLayout.setVerticalGroup(
            authorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(authorsPanelLayout.createSequentialGroup()
                .addComponent(editedTagsScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deleteAuthorButton)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, authorsPanelLayout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        addPhotoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/addPhotoNews.png"))); // NOI18N
        addPhotoButton.setText("Add photo");
        addPhotoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPhotoButtonActionPerformed(evt);
            }
        });

        updateButton.setText("Save changes");
        updateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateButtonActionPerformed(evt);
            }
        });

        jButton1.setText("Reset");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout newsEditorPanelLayout = new javax.swing.GroupLayout(newsEditorPanel);
        newsEditorPanel.setLayout(newsEditorPanelLayout);
        newsEditorPanelLayout.setHorizontalGroup(
            newsEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newsEditorPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(newsEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(newsEditorPanelLayout.createSequentialGroup()
                        .addGroup(newsEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(generalPanel, 0, 479, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(newsEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(addPhotoButton)
                            .addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(newsEditorPanelLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(authorsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(142, 142, 142))
            .addGroup(newsEditorPanelLayout.createSequentialGroup()
                .addGap(211, 211, 211)
                .addComponent(updateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(212, Short.MAX_VALUE))
        );
        newsEditorPanelLayout.setVerticalGroup(
            newsEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newsEditorPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(newsEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(newsEditorPanelLayout.createSequentialGroup()
                        .addComponent(generalPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(newsEditorPanelLayout.createSequentialGroup()
                        .addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(addPhotoButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(newsEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(authorsPanel, 0, 185, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(newsEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(updateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18))
        );

        newsEditorPanel.setBounds(0, 0, 680, 500);
        jDesktopPane1.add(newsEditorPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE)
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void newsListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newsListButtonActionPerformed
        // TODO add your handling code here:
        p2piki.viewListNews();
}//GEN-LAST:event_newsListButtonActionPerformed

    private void deleteNewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteNewButtonActionPerformed
        // TODO add your handling code here:
        deleteInternalFrame.setVisible(true);
        deleteInternalFrame.setLocation(150, 150);
}//GEN-LAST:event_deleteNewButtonActionPerformed

    private void addNewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNewButtonActionPerformed
        // TODO add your handling code here:
        p2piki.viewNewsEdition(null);
}//GEN-LAST:event_addNewButtonActionPerformed

    private void addPersonalTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPersonalTagButtonActionPerformed
        // TODO add your handling code here:
        if (addTagTextField.getText().trim().length() == 0) {
            p2piki.addError("You can't add a void tag.");
        } else {
            Tag tag = new PersonalTag();
            tag.setTag(addTagTextField.getText().trim());
            addTagTextField.setText("");
            auxTagsList.add(tag);
            editedTagsModel.addElement(tag.getTag());
        }
}//GEN-LAST:event_addPersonalTagButtonActionPerformed

    private void addOntologyTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOntologyTagButtonActionPerformed
        // TODO add your handling code here:
        if (addOntologyTagTextField.getText().trim().length() == 0
                || !addOntologyTagTextField.isEnabled()) {
            p2piki.addError("You can't add a void tag or without a category.");
        } else {
            String keyword = addOntologyTagTextField.getText().trim();
            boolean keywordExists = false;
            List taxonomy;
            for (int i = 0; i < taxonomies.size(); i++) {
                taxonomy = (List) taxonomies.get(i);
                for (int j = 0; j < taxonomy.size(); j++) {
                    if (((String) taxonomy.get(j)).equals(keyword)) {
                        keywordExists = true;
                    }
                }
            }
            if (!keywordExists) {
                p2piki.addError("The Tag doesn't exist in the database.");
                return;
            }
            PredefinedTag tag = new PredefinedTag();
            tag.setTag(addOntologyTagTextField.getText().trim());
            tag.setCategory((String) categoriesComboBox.getSelectedItem());
            addOntologyTagTextField.setText("");
            auxTagsList.add(tag);
            editedTagsModel.addElement(tag.getTag());
        }
}//GEN-LAST:event_addOntologyTagButtonActionPerformed

    private void addOntologyTagTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_addOntologyTagTextFieldKeyReleased
        // TODO add your handling code here:
        String text = addOntologyTagTextField.getText();
        List tax = (List) taxonomies.get(categoriesComboBox
                .getSelectedIndex() - 1);
        Collections.sort(tax);
        ontologiesPopupMenu = new javax.swing.JPopupMenu();
        for (int i = 1; i < tax.size(); i++) {
            if (((String) tax.get(i)).toLowerCase().startsWith(
                    text.toLowerCase())) {
                final javax.swing.JMenuItem item =
                        new javax.swing.JMenuItem(
                        (String) tax.get(i));
                item.addActionListener(
                        new java.awt.event.ActionListener() {

                            @Override
                            public void actionPerformed(
                                    java.awt.event.ActionEvent e) {
                                addOntologyTagTextField.setText(
                                        item.getText());
                            }
                        });
                ontologiesPopupMenu.add(item);
            }
        }
        ontologiesPopupMenu.show(addOntologyTagTextField,
                addOntologyTagTextField.getX() - 5,
                addOntologyTagTextField.getY() + 10);
        addOntologyTagTextField.grabFocus();
}//GEN-LAST:event_addOntologyTagTextFieldKeyReleased

    private void categoriesComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_categoriesComboBoxItemStateChanged
        // TODO add your handling code here:
        if (categoriesComboBox.getSelectedIndex() > 0) {
            addOntologyTagTextField.setEnabled(true);
            addOntologyTagTextField.setText("");
        } else {
            addOntologyTagTextField.setEnabled(false);
            addOntologyTagTextField.setText("Choose a category");
        }
}//GEN-LAST:event_categoriesComboBoxItemStateChanged

    private void editedTagsListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_editedTagsListValueChanged
        // TODO add your handling code here:
}//GEN-LAST:event_editedTagsListValueChanged

    private void editedTagsListFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_editedTagsListFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_editedTagsListFocusLost

    private void deleteTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteTagButtonActionPerformed
        // TODO add your handling code here:
        if (editedTagsList.getSelectedValue() != null) {
            auxTagsList.remove(editedTagsList.getSelectedIndex());
            editedTagsModel.removeElementAt(editedTagsList.getSelectedIndex());
        }
}//GEN-LAST:event_deleteTagButtonActionPerformed

    private void authorsListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_authorsListValueChanged
        // TODO add your handling code here:
}//GEN-LAST:event_authorsListValueChanged

    private void authorsListFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_authorsListFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_authorsListFocusLost

    private void deleteAuthorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteAuthorButtonActionPerformed
        // TODO add your handling code here:
        if (authorsList.getSelectedValue() != null) {
            auxAuthorsList.remove(authorsList.getSelectedIndex());
            authorsModel.removeElementAt(authorsList.getSelectedIndex());
        }
}//GEN-LAST:event_deleteAuthorButtonActionPerformed

    private void addAuthorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAuthorButtonActionPerformed
        // TODO add your handling code here:
        if (nameTextField.getText().trim().length() == 0) {
            p2piki.addError("You can't add a void tag.");
        } else {
            Author a = new grupb.upf.XMLObjects.impl.Author();
            a.setName(nameTextField.getText().trim());
            a.setSurname(surnameTextField.getText().trim());
            a.setAccount(accountTextField.getText().trim());
            nameTextField.setText("");
            surnameTextField.setText("");
            accountTextField.setText("@gmail.com");
            auxAuthorsList.add(a);
            authorsModel.addElement(a.getName() + " " + a.getSurname());
        }
}//GEN-LAST:event_addAuthorButtonActionPerformed

    private void deleteYesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteYesButtonActionPerformed
        // TODO add your handling code here:
        deleteInternalFrame.setVisible(false);
        deleteNew();
}//GEN-LAST:event_deleteYesButtonActionPerformed

    private void deleteNoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteNoButtonActionPerformed
        // TODO add your handling code here:
        deleteInternalFrame.setVisible(false);
}//GEN-LAST:event_deleteNoButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        getProperties();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateButtonActionPerformed
        // TODO add your handling code here:
        updateNewProperties();
        if (nw.getID() == -1) {
            if (p2piki.addNew(nw)) {
                p2piki.addInfo("New added correctly.");
            } else {
                p2piki.addError("Error adding the new.");
            }
        } else {
            if (p2piki.updateNew(nw)) {
                p2piki.addInfo("New updated correctly.");
            } else {
                p2piki.addError("Error updating the new.");
            }
        }
    }//GEN-LAST:event_updateButtonActionPerformed

    private void addPhotoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPhotoButtonActionPerformed
        // TODO add your handling code here:
        FileSystemView fsv = new FileChooser(
                new File(grupb.upf.util.Config.getProperty("photo.folder"))
                .getAbsoluteFile());
        JFileChooser fc = new JFileChooser(fsv);
        fc.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
        if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            String path = fc.getSelectedFile().getAbsolutePath();
            boolean isPhoto = false;
            //format
            final String extension =
                    path.substring(path.lastIndexOf(".") + 1);
            for (int i = 0; i < PHOTO_FORMATS.length; i++) {
                if (PHOTO_FORMATS[i].equalsIgnoreCase(extension)) {
                    isPhoto = true;
                }
            }
            if (isPhoto) {
                path = path.replaceAll("\\\\", "/");
                int index = path.indexOf(grupb.upf.util.Config.getProperty(
                        "photo.folder")) +
                        grupb.upf.util.Config.getProperty("photo.folder")
                        .length();
                path = path.substring(index);
                Photo p = p2piki.getPhoto(path);
                if (p != null) {
                    body.append("\n<photo id=\"" + p.getID() + "\"></photo>\n");
                } else {
                    p2piki.addError("The photo isn't in the database, please insert it in the DB first.");
                }
            } else {
                p2piki.addError("It isn't an accepted format.");
            }
        }
    }//GEN-LAST:event_addPhotoButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField accountTextField;
    private javax.swing.JButton addAuthorButton;
    private javax.swing.JButton addNewButton;
    private javax.swing.JButton addOntologyTagButton;
    private javax.swing.JTextField addOntologyTagTextField;
    private javax.swing.JButton addPersonalTagButton;
    private javax.swing.JButton addPhotoButton;
    private javax.swing.JTabbedPane addTagTabbedPane1;
    private javax.swing.JTextField addTagTextField;
    private javax.swing.JList authorsList;
    private javax.swing.JPanel authorsPanel;
    private javax.swing.JTextArea body;
    private javax.swing.JComboBox categoriesComboBox;
    private javax.swing.JLabel categoryLabel1;
    private javax.swing.JButton deleteAuthorButton;
    private javax.swing.JInternalFrame deleteInternalFrame;
    private javax.swing.JButton deleteNewButton;
    private javax.swing.JButton deleteNoButton;
    private javax.swing.JButton deleteTagButton;
    private javax.swing.JButton deleteYesButton;
    private javax.swing.JList editedTagsList;
    private javax.swing.JScrollPane editedTagsScrollPane1;
    private javax.swing.JScrollPane editedTagsScrollPane2;
    private javax.swing.JPanel generalPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JPanel newsEditorPanel;
    private javax.swing.JButton newsListButton;
    private javax.swing.JPopupMenu ontologiesPopupMenu;
    private javax.swing.JPanel ontologyTagPanel1;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JPanel personalTagPanel1;
    private javax.swing.JTextField source;
    private javax.swing.JLabel sourceLabel;
    private javax.swing.JLabel subjectLabel;
    private javax.swing.JTextField subtitle;
    private javax.swing.JTextField surnameTextField;
    private javax.swing.JTextField title;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JButton updateButton;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
